using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Web.Core;
using Web.Core.Objects;

public partial class AdminCP_Manufacturers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (Session["Language"] == null)
            Session["Language"] = Web.Core.GlobalStorage.Language.English;
        int page = 1; 
        int pageSize = GlobalStorage.manufacturersPerPageForAdmin;
        if (Request.Params["page"] != null)
            page = int.Parse(Request.Params["page"]);
        ArrayList arrManufacturers = Manufacturers.GetAllManufacturers(page,pageSize);

        if (!IsPostBack)
        {
            this.rptManufacturers.DataSource = arrManufacturers;
            this.rptManufacturers.DataBind();
        }

        // Pager
        this.Pager1.objectsPerPage = GlobalStorage.manufacturersPerPageForAdmin;
        this.Pager1.displayAll = false; // Chi hien thi ben phai
        this.Pager1.totalObjects = Manufacturers.GetAllManufacturers().Count;
        // ---------------
        if (Request.Params["do"] != null)
        {
            string mDo = Request.Params["do"];
            switch (mDo)
            {
                case "edit":
                    if (Request.Params["mid"] != null)
                        LoadControls();
                    break;
                case "add":
                    LoadControls();
                    break;
                case "del":
                    if (Request.Params["mid"] != null)
                    {
                        int manID = 0;
                        try
                        {
                            manID = int.Parse(Request.Params["mid"].ToString());
                        }
                        catch { }
                        Manufacturers.DeleteManufacturer(new Manufacturer(manID,"",""));
                        this.PreRenderComplete += new EventHandler(AdminCP_Manufacturers_PreRenderComplete);                        
                    }
                    break;
                default:
                    break;
            }
        }
    }

    void AdminCP_Manufacturers_PreRenderComplete(object sender, EventArgs e)
    {
        Response.Redirect("Manufacturers.aspx");
    }
    void LoadControls()
    {
        Control addEditManufacturers = (Control)Page.LoadControl("~/AdminCP/AdminControls/AddEditManufacturer.ascx");
        this.PlaceHolderBottom.Controls.Add(addEditManufacturers);
    }
}
